---
layout: blog-default
title: All Posts
---
<div class="m-all">
    <div class="main">
        <h1 class="js-page-heading">All Posts</h1>
        {% include blog/tags.html %}
        <!--group by year: http://stackoverflow.com/questions/19086284/jekyll-liquid-templating-how-to-group-blog-posts-by-year-->
        <section class="js-year-wrapper">
            {% for post in site.posts %}
                {% assign currentdate = post.date | date: "%Y" %}
                {% if currentdate != date %}
                    {% unless forloop.first %}</ul></section>{% endunless %}
                    <section id="{{ post.date | date: "%Y" }}">
                    <h2 class="year-title" id="year-{{ post.date | date: "%Y" }}">{{ currentdate }}</h2>
                    <ul class="year-list">
                    {% assign date = currentdate %}
                {% endif %}
                <li class="js-post-block {% for tag in post.tags %} tag-{{ tag }} {% endfor %}">
                    <span class="post-date">{{ post.date | date:"%b %d" }}</span><a class="post-link" href="{{ post.url | prepend: site.baseurl | replace: '//', '/' }}">{{ post.title }}</a>
                </li>
                {% if forloop.last %}</ul></section>{% endif %}
            {% endfor %}
        </section>
    </div>
</div>

<script type="text/javascript">
    // function queryString is copied from
    // http://stackoverflow.com/questions/979975/how-to-get-the-value-from-url-parameter#answer-979995
    function queryString() {
      // This function is anonymous, is executed immediately and
      // the return value is assigned to QueryString!
      var query_string = {};
      var query = window.location.search.substring(1);
      var vars = query.split("&");
      for (var i=0;i<vars.length;i++) {
        var pair = vars[i].split("=");
        // If first entry with this name
        if (typeof query_string[pair[0]] === "undefined") {
            query_string[pair[0]] = pair[1];
        // If second entry with this name
        } else if (typeof query_string[pair[0]] === "string") {
            var arr = [ query_string[pair[0]], pair[1] ];
            query_string[pair[0]] = arr;
        // If third or later entry with this name
        } else {
            query_string[pair[0]].push(pair[1]);
        }
      }
        return query_string;
    }

    $(function() {
        var $pageHeading = $('.js-page-heading');
        var $articleTag = $('.js-article-tag');
        var $tagShowAll = $('.js-tag-show-all');
        var $postBlock = $('.js-post-block');
        var $yearSection = $('.js-year-wrapper section');

        window.tagSelect = function(tag) {
            if (tag === undefined || tag === '') {
                $pageHeading.text('All Posts');
                $tagShowAll.focus();
                $postBlock.show();
            } else {
                $pageHeading.text('Tag: ' + tag);
                $postBlock.not('.tag-' + tag).hide();
                $articleTag.filter('.tag-' + tag).focus();
                $postBlock.filter('.tag-' + tag).show();
            }
            $yearSection.each(function() {
                var liAllShow = false;
                var $this = $(this);
                var $lis = $this.find('li');
                for (var i = 0; i < $lis.length; i++) {
                    if($($lis[i]).css('display') !== 'none') {
                        liAllShow = true;
                        break;
                    }
                }
                if (liAllShow === false) {
                    $this.hide();
                } else {
                    $this.show();
                }
            });
            tag === undefined || window.history.replaceState(null, '', window.location.href.split('?')[0] + '?tag=' + tag);
        }
        var query = queryString();
        var tag = undefined;
        query.tag === undefined || (tag = decodeURI(query.tag));
        tagSelect(tag);
    });
</script>
